function rea(){
	var url = 'http://'+window.location.host+document.getElementById('form').getAttribute('action',1);
	var url1 = url.replace(/\//g,"\\\/");
	var reg=eval("/"+url1+"\\/index/i");
	var str = window.location.href;
	if(reg.exec(str) || str == url){
		$('#act_word').val('');
		document.body.style.visibility='visible';
	}else{
		document.getElementById('form').submit();
	}
}

function sort_search(key,val,word){
	var key_arr = new Array();
	key_arr = key.split(',');
	var val_arr = new Array();
	val_arr = val.split(',');
	var len = key_arr.length;
	for(var i = 0; i<len; i++){
		$('#'+key_arr[i]).val(val_arr[i]);
	}
	
	var word_arr = new Array();
	word_arr = word.split(',');
	$('#'+word_arr[0]).val(word_arr[1]);
	
	$('#p').val('');
	$('#ps').val('');
	getid('form').submit();
}

function clear_sort(name,i){
	if(i == null){
		document.getElementById('word_'+name).value = '全部';
		i=1;
	}else{
		i++;
	}
	if( document.getElementById(name+String(i)) ){
		document.getElementById(name+String(i)).value = '';
		clear_sort(name,i);
	}else{
		getid('form').submit();
	}
}

function bg(obj){
	var objj = $(obj);
	objj.css('background-color','#FFF');
	//objj.find("span[name='menus']").css('display','inline');
	objj.mouseout(function(){
		objj.css('background-color','');
		//objj.find("span[name='menus']").css('display','none');
	});
	
}

function bg_select(obj){
	var oobj = $('#c_'+obj.id);
	var panduan = $('#'+obj.id).attr('checked');
	if(panduan==true || panduan=='checked'){
		oobj
		.unbind('mouseover').unbind('mouseout').removeAttr('onmouseover')
		.css('background-color','#DDD');
	}else{
		$('#chkall').attr("checked",false)
		oobj.bind('mouseover',function(){bg(oobj);})
		.css('background-color','');
	}
	
}

jQuery.fn.def = function(text){
	obj = this;
	text = text==null?'请输入关键字':text;
	obj.val(text).css('color','#999')
	   .bind({
		blur:function(){
					if(obj.val()=='' || obj.val()==text){
						obj.css('color','#999').val(text);
					} 
				},
		focus:function(){
					obj.css('color','#000')
					if(obj.val()==text){
						obj.val('');
					}
				}
		});
}


function checkall(form, prefix) {
	var check = $('#chkall').attr("checked")
	if(check!='checked' && check !=true){check=false}
	$("input[type='checkbox']").each(function(){
		if(this.id!='chkall'){
			$(this).attr("checked",check);
			bg_select(this);
		}
	})
}

function cancelall(){
	$("input[type='checkbox']").each(function(){
		$(this).attr("checked",false);
	})
}

function op(op,value,id){
	
	//删除
	if(op == 'del'){
		var s = confirm("真的要删除选中的记录吗?");
		if(s){
			loading();
			if(id){
				cancelall();
				$('#'+id).attr('checked',true);
			}
			getid('form').action = getid('form').action+'/'+op;
			getid('form').submit();
		}
	}
	//清空
	else if(op == 'clean'){
		var s = confirm("真的要删除所有记录吗?");
		if(s){
			loading();
			getid('form').action = getid('form').action+'/'+op;
			getid('form').submit();
		}
	}
	//增加显示
	else if(op == 'ps'){
		var ps = prompt('每页显示多少条记录?','10');
		getid('p').value = 1;
		getid('ps').value = ps;
		getid('form').submit();
	}
	//改排序 order
	else if(op == 'order'){
		if(getid('order').value == value){
			//改升降顺
			if(getid('by').value == 'ASC'){getid('by').value = 'DESC';}
			else{getid('by').value = 'ASC';}
		}else{
			//改order边个
			getid('order').value = value;
			getid('by').value = 'ASC';
			getid('p').value = 1;
		}
		getid('form').submit();
	}
	//开关制
	else if(op == 'onoff'){
		loading();
		if(id){
			cancelall();
			$('#'+id).attr('checked',true);
		}
		getid('form').action = getid('form').action+'/'+op;
		getid('value').value = value;
		getid('form').submit();
	}
	//换页 page
	else if(op == 'page'){
		var page = value.split(",");
		if(page[0] == '+'){
			if(Number(page[1])+1 <= page[2]){
				getid('p').value = Number(page[1])+1;
				getid('form').submit();
			}
		}
		else if(page[0] == '-'){
			if(page[1] != 1){
				getid('p').value = Number(page[1])-1;
				getid('form').submit();
			}
		}else{
			if(Number(page[0]) <= Number(page[1])){
				getid('p').value = page[0];
				getid('form').submit();
			}
		}
	}
	//转到
	else if(op == 'goto'){
		loading();
		var p = prompt('要转到第几页? (1-'+value+')','');
		if(p>0 && p<=value){
			getid('p').value = p;
			getid('form').submit();
		}
	}
	//进入目录
	else if(op == 'gotolv'){
		var lv = Number(getid('lv').value);
		if(lv == 4){
			alert('不能再进入');
		}else{
			getid('kw').value = '';
			getid('p').value = 1;
			getid('fid').value = value;
			getid('lv').value = lv + 1;
			getid('form').submit();
		}
	}
	//返回上级目录
	else if(op == 'backlv'){
		var lv = Number(getid('lv').value);
		getid('kw').value = '';
		getid('p').value = 1;
		getid('act').value = op;
		getid('lv').value = lv - 1;
		getid('form').submit();
	}
	else{
		loading();
		getid('form').action = getid('form').action+'/'+op;
		getid('form').submit();
	}
	
	function loading(){
		document.getElementById('AW').style.display='none';
		document.getElementById('load').style.display='';
		
	}
}